<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get a SimpleXMLElement object from a DOM node</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.simplexml.html">« SimpleXML 函数</a></li>
      <li style="float: right;"><a href="function.simplexml-load-file.html">simplexml_load_file »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.simplexml.html">SimpleXML 函数</a></li>
    <li>Get a SimpleXMLElement object from a DOM node</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.simplexml-import-dom" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">simplexml_import_dom</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">simplexml_import_dom</span> &mdash; <span class="dc-title">Get a <code class="literal">SimpleXMLElement</code> object from a DOM node</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.simplexml-import-dom-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>simplexml_import_dom</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span>|<span class="type"><a href="class.domnode.html" class="type DOMNode">DOMNode</a></span></span> <code class="parameter">$node</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$class_name</code><span class="initializer"> = SimpleXMLElement::class</span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span></span></div>

  <p class="para rdfs-comment">
   This function takes a node of a <a href="book.dom.html" class="link">DOM</a>
   document and makes it into a SimpleXML node. This new object can
   then be used as a native SimpleXML element. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.simplexml-import-dom-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">node</code></dt>

     <dd>

      <p class="para">
       A <a href="book.dom.html" class="link">DOM</a> Element node
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">class_name</code></dt>

     <dd>

      <p class="para">
       You may use this optional parameter so that
       <span class="function"><strong>simplexml_import_dom()</strong></span> will return an object of 
       the specified class. That class should extend the 
       <span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> class.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.simplexml-import-dom-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a <span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> or <strong><code>null</code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.simplexml-import-dom-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5473">
    <p><strong>示例 #1 Importing DOM</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;books&gt;&lt;book&gt;&lt;title&gt;blah&lt;/title&gt;&lt;/book&gt;&lt;/books&gt;'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$dom</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error&nbsp;while&nbsp;parsing&nbsp;the&nbsp;document'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$s&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">simplexml_import_dom</span><span style="color: #007700">(</span><span style="color: #0000BB">$dom</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">book</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
blah
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.simplexml-import-dom-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.dom-import-simplexml.html" class="function" rel="rdfs-seeAlso">dom_import_simplexml()</a> - Gets a DOMElement object from a
   SimpleXMLElement object</span></li>
    <li class="member"><a href="simplexml.examples-basic.html" class="xref">Basic SimpleXML usage</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>